package com.zpb.admin.controller;

import com.zpb.admin.domain.dto.MenuQueryDto;
import com.zpb.admin.domain.vo.RoleMenuTreeSelectVo;
import com.zpb.framework.domain.vo.MenuTreeSelectVo;
import com.zpb.admin.service.MenuService;
import com.zpb.framework.domain.ApiResult;
import com.zpb.admin.domain.vo.MenuVo;
import com.zpb.framework.domain.entity.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/21
 */
@RestController
@RequestMapping("/system/menu")
public class SysMenuController {
    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public ApiResult<List<MenuVo>> getMenuList(MenuQueryDto menuQueryDto){
        return menuService.getMenuListByCondition(menuQueryDto);
    }
    @PostMapping
    public ApiResult addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }
    @GetMapping("/{id}")
    public ApiResult<MenuVo> getMenuById(@PathVariable("id") Long id){
        return menuService.getMenuById(id);
    }
    @PutMapping
    public ApiResult updateMenu(@RequestBody Menu menu){
        return menuService.updateMenuById(menu);
    }
    @DeleteMapping("/{menuId}")
    public ApiResult deleteMenuById(@PathVariable("menuId") Long id){
        return menuService.deleteMenuById(id);
    }
    @GetMapping("/treeselect")
    public ApiResult<List<MenuTreeSelectVo>> getMenuTreeSelect(){
        return menuService.getMenuTreeSelect();
    }
    @GetMapping("/roleMenuTreeselect/{id}")
    public ApiResult<RoleMenuTreeSelectVo> getRoleMenuTreeSelect(@PathVariable("id") Long roleId){
        RoleMenuTreeSelectVo roleMenuTreeSelectVo = new RoleMenuTreeSelectVo();
        roleMenuTreeSelectVo.setMenus(menuService.getMenuTreeSelect().getData());
        roleMenuTreeSelectVo.setCheckedKeys(menuService.getCheckedKeysByRoleId(roleId));
        return ApiResult.success(roleMenuTreeSelectVo);
    }

}
